一般机器
- 1.
su -- 2.
sudo su或者su root - 3.
sudo passwd root或者passwd roo 4.
vim /etc/ssh/sshd_config5.找到
PermitRootLogin并用#注释掉当前行# PermitRootLogin prohibit-password添加:
PermitRootLogin yes6.找到
PasswordAuthentication no,把no改成yesPasswordAuthentication no- 7.键入
esc输入:wq保存退出 - 8.service ssh restart
AWS Lightsail
开机root脚本
#!/bin/bash
# 1. 设置 root 账号密码
echo "root:Qq469566135+" | chpasswd
# 2. 修改 SSH 配置,允许 root 账号 + 密码登录
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed -i 's/^#\?ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config
# 3. 重启 SSH 服务使配置生效
systemctl restart ssh
systemctl enable sshAWS EC2
创建机器的时候,添加如下启动脚本
echo root:Qq469566135+ |sudo chpasswd root sudo sed -i 's/^.*PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config; sudo sed -i 's/^.*PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config; sudo reboot
如果已经创建好了机器
创建虚拟机的时候,下载秘钥,通过秘钥登录(登录用户名为centos)。
创建root的密码(会提示你输入new password,输入一个你要设置的root的密码,需要你再输入一遍进行验证。)
sudo passwd root切换到root身份(输入你刚刚设置的密码。)
su root编辑ssh登录方式(找到 PasswordAuthentication no,把no改成yes。)
vi /etc/ssh/sshd_config- 某些情况可能还需要把PermitRootLogin forced-commands-onlyi 改成 PermitRootLogin yes
- 否则可能会提示:Permission denied, please try again.
重启一下sshd服务
sudo /sbin/service sshd restart
到此可以用root身份的账号密码直接登录EC2的服务器了,不需要使用秘钥了。
甲骨文
sudo -i
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;service sshd restartsudo -iecho root:Qq469566135+ |sudo chpasswd root
sudo sed -i 's/^#?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
service sshd restart
其他一般 Debian 9/Ubuntu
其他一般 Debian 9/Ubuntu
先通过ssh登录vps主机,比如默认用户名是ubuntu
登录成功后,输入su,获取root权限,输入密码,命令行显示root账号
- 1、修改ssh配置文件:vim /etc/ssh/sshd_config
在#PermitRootLogin without-password 此行下新增一行:
PermitRootLogin yes
在该段的其他行前面都加上#注释掉,只保留PermitRootLogin yes这行,不然还是无法登录。
保存退出
- 2.重启ssh。输入命令
service sshd restartAzure Linux虚拟机
Azure Linux虚拟机
Azure创建Linux的虚拟机的时候,在创建用户的时候并没有提示设置root用户密码,而只是让新建一个普通用户。没有root权限导致无法进行一些特殊操作。
Linux主机获取root权限的方法有:
- 为root用户设置密码(设置完后,可以以root身份,用设置的密码登录)
sudo passwd root
```
2. `sudo su –` (密码为当前用户密码)
3. `sudo +相应的命令` (密码为当前用户密码)
http://www.iteait.com/archives/549
©版权声明
文章版权归作者所有,未经允许请勿转载。
THE END

评论已关闭